package org.rency.crawler.fetch.repository.impl;

import javax.annotation.Resource;
import org.rency.crawler.common.enums.PolicyState;
import org.rency.crawler.fetch.repository.MetaResourceRepository;
import org.rency.crawler.fetch.repository.RobotsPolicyRepository;
import org.rency.crawler.integration.cache.RobotsCacheClient;
import org.springframework.stereotype.Repository;

/**
 * 名称:RobotsPolicyRepositoryImpl
 * 描述:${TODO}
 *
 * @author:rency
 * @version:V1.0.0
 * @JDK 1.8
 * @since 2017/11/23 21:28
 */
@Repository
public class RobotsPolicyRepositoryImpl implements RobotsPolicyRepository {

  @Resource
  private MetaResourceRepository metaResourceRepository;

  @Resource
  private RobotsCacheClient robotsCacheClient;

  @Override
  public PolicyState get(String fetchNo) {
    return robotsCacheClient.get(fetchNo);
  }

  @Override
  public boolean save(String fetchNo, PolicyState state) {
    robotsCacheClient.set(fetchNo,state,metaResourceRepository.getRobotsPolicyExpireTime());
    return true;
  }
}
